//DS18B20温度传感器
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>

const int oneWireBus = 4;     // 选择DS18B20数字信号连接的IO口

OneWire oneWire(oneWireBus);    // 设置oneWire实例可与任意OneWire器件通信

DallasTemperature sensors(&oneWire);    // 将oneWire参数提供给Dallas温度传感器 

void setup()
{
  Serial.begin(115200);
  sensors.begin();
}

void loop() 
{
  sensors.requestTemperatures(); 
  float temperatureC = sensors.getTempCByIndex(0);
  float temperatureF = sensors.getTempFByIndex(0);
  Serial.print(temperatureC);
  Serial.println("ºC");
  Serial.print(temperatureF);
  Serial.println("ºF");
  delay(1000);
}
